#!/usr/bin/env python
from os import path
Import('build env module')

env.Append(LIBPATH=[build.get_module('tiapp').dir])
env.Append(CPPPATH = ['%s/modules/ti.App' % build.titanium_source_dir])

build.add_thirdparty(env, 'poco')
build.add_thirdparty(env, 'webkit')
env.Append(LIBS=['tiappmodule'])

sources = Glob('*.cpp') + ['url/URLUtils.cpp']
if build.is_linux():
    sources = sources + Glob('gtk/*.cpp')
    env.Append(LIBS=['Xss', 'libsoup-2.4', 'libsoup-gnome-2.4'])
    env.ParseConfig('PKG_CONFIG_PATH=${PKG_CONFIG_PATH} pkg-config --cflags --libs libnotify gtk+-2.0 gdk-2.0 x11 xext libsoup-2.4 libsoup-gnome-2.4')

elif build.is_win32():
    build.add_thirdparty(env, 'cairo')
    sources = sources + Glob('win/*.cpp')
    sources += Glob('binding/kjs*.cpp')
    env.Append(CPPPATH=[build.tp('icu', 'include')])
    env.Append(LIBS=[
        'kernel32', 'shell32', 'user32', 'ole32', 'comdlg32', 'comctl32',
        'gdi32', 'shlwapi', 'oleaut32', 'icuuc', 'pthreadVC2', 'libcurl_imp',
        'comsuppw', 'advapi32'])
    env.Append(CCFLAGS=['/MD', '/DUNICODE', '/D_UNICODE'])
    env.Append(LINKFLAGS=['/NODEFAULTLIB:LIBCMT.lib', '/LTCG', '/INCREMENTAL:NO', '/OPT:REF'])

elif build.is_osx():
    env.Append(FRAMEWORKPATH=[build.tp('growl')])
    env.Append(FRAMEWORKS=['Cocoa','Carbon', 'IOKit', 'Growl'])
    sources = sources + Glob('mac/*.mm') + Glob('mac/*.cpp')
    env.Append(CCFLAGS=['-x', 'objective-c++'])

# Copy the support files the module build directory
build.utils.LightWeightCopy(path.join(build.cwd(), 'support'), module.dir)
build.mark_build_target(env.SharedLibrary(
    path.join(module.dir,'tiuimodule'), sources))
